<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ajout facture</title>


<!---------------------for autocomplete--------------->
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-1.11.0.min.js');?>" ></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-ui-1.10.4/js/jquery-ui-1.10.4.min.js');?>" ></script>
	<link href="<?php echo base_url("assets/css/jquery-ui.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form css ----------------------->
	<link href="<?php echo base_url("assets/css/pure.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form validation ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.validate.js');?>" ></script>
<!---------------------for form mask input ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.mask.min.js');?>" ></script>


</head>
<body>
<?php
include_once('header.php');
//$r1=$fournisseur['rec'];  // one fournisseur
$r2=$liste_fourn['rec'];  // list of all fournisseur for autocomplete
$r3=$liste_article['rec']; // list of all activities for auto complete

// ----- populate $liste_des_fournisseurs array for autocomplete ----- //
$liste_des_fournisseurs = array();
foreach ($r2 as $lf){
	array_push($liste_des_fournisseurs, $lf->nom);
}
// ----- populate $liste_des_activites array for autocomplete ----- //
$liste_des_articles = array();
foreach ($r3 as $lda){
	array_push($liste_des_articles, $lda->nom_art);
	
}

?>
<?php
echo form_open_multipart( base_url('facture_ctr/ajout_new1') ); 

?>

<form id="fournisseur_frm" class="pure-form pure-form-stacked" method="POST" action="<?php echo base_url('facture_ctr/ajout_new1') ;?>">
    <fieldset>
        <legend style="font-size: 150%">اضافة فاتورة</legend>

        <div class="pure-g">
            <div class="pure-u-1 pure-u-md-1-3">
                <label for="fournisseur">المورد </label>
				<input id="nom" name="fournisseur" type="text" value="">
            </div>
            
			 <div class="pure-u-1 pure-u-md-1-3">
                <label for="address">الرقم </label>
                <input id="numero_fact" name="numero" type="text" value="">
            </div>
			
        
			
			<div class="pure-u-1 pure-u-md-1-3">
                <label for="address">الطبيعة </label>
               
				<select  name="t" class="ltr">
                 <option value="bc">وصل طلب</option>
                 <option value="convention">اتفاقية</option>
				 <option value="autre">اخرى</option>
 
                </select>
            </div>
			
		
			
		
			
        </div>

      <input type="submit" value="اضافة"  class="pure-button pure-button-primary" />
	 <?php echo' <a href="'.base_url("facture_ctr/index_test/").'" class="pure-button pure-button-primary">خروج</a> '?>

    
    </fieldset>
</form>

</body>
<script>
$(function() {
	

var liste_fourniss = <?php echo json_encode($liste_des_fournisseurs); ?>;
var liste_article = <?php echo json_encode($liste_des_articles); ?>;

$( "#nom" ).autocomplete({source: liste_fourniss});
$( "#article" ).autocomplete({source: liste_article});


});

//---

$('#submit_btn').click(function() {
  if($("[class^=error]").is(":visible")){
    alert('منالك حقل / حقول إدخال غير مطابقة !');
    return false;
  } else {
  	$('#fournisseur_frm').submit();
    return false;
  }
});


$('#numero').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-rc').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    //var characterReg = /^([a-zA-Z0-9]{7,16})$/;
    var characterReg = /^([0-9]{1,3})$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-rc" flag="required" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});
$('#mondat').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-rc').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    //var characterReg = /^([a-zA-Z0-9]{7,16})$/;
    var characterReg = /^([0-9]{1,3})$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-rc" flag="required" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});




//---* maskage below 
$('#numero').mask('AAA', {'translation': {
                                        A: {pattern: /[0-9]/},
										O: {pattern: /[0-9]/, optional: true},
										D: {pattern: /[a-zA-Z]/}
                                      }
                                });

//---* maskage below 
$('#mondat').mask('AAA', {'translation': {
                                        A: {pattern: /[0-9]/},
										O: {pattern: /[0-9]/, optional: true},
										D: {pattern: /[a-zA-Z]/}
                                      }
                                });





</script>
</html>